package put.cs.two.tsp.experiments;

import put.cs.two.to.tsp.calculators.base.AbstractExperiment;
import put.cs.two.to.tsp.calculators.base.AbstractTSPSolutionCalculator;
import put.cs.two.to.tsp.calculators.implementation.greedy.CycleExtensionCalculator;
import put.cs.two.to.tsp.models.NodeSet;
import put.cs.two.to.tsp.models.TSPSolution;

public class GreedyCycleExtensionSearchExperiment extends AbstractExperiment {

    @Override
    public TSPSolution doWork(NodeSet nodeSet) {
        int minCycleLength = Integer.MAX_VALUE;
        TSPSolution bestSolution = null;
        for (int i = 1; i <= nodeSet.getSize(); i++) {
            AbstractTSPSolutionCalculator calculator = new CycleExtensionCalculator();
            TSPSolution solution = calculator.solve(nodeSet, i);
            if (solution.getCycleLength() < minCycleLength) {
                minCycleLength = solution.getCycleLength();
                bestSolution = solution;
            }
            System.out.println(solution);
        }
        return bestSolution;
    }
}
